/*
 * lib2Desa - Another 2D game library in C++
 * Copyright (C) 2009 Erivaldo Xavier de Lima Filho
 *
 * This program is free software and is distributed under GNU General Public License version 3. You can modify and/or redistribute
 * it under the terms of GPL version 3 or posterior version. This program comes with NO WARRANTY, for more details, see LICENSE,
 * or <http://www.gnu.org/licenses>.
 *
 * Contact info:
 *
 *	Erivaldo Xavier de Lima Filho, desadoc@gmail.com
 *
 */

#include "Lua/Game.hpp"

#include "Core/Game.hpp"
#include "Core/IGraphicDevice.hpp"
using namespace lib2Desa;

#include <iostream>
using namespace std;

int Game_new(lua_State* L)
{
	IGraphicDevice** gd = (IGraphicDevice**) lua_touserdata(L,1);
	Game* _new = new Game(*gd);
	
	size_t nbytes = sizeof(_new);
	Game **ud = (Game**) lua_newuserdata(L, nbytes);
	(*ud) = _new;
	
    luaL_getmetatable(L, "lib2Desa.Game");
	
	lua_pushstring(L, "__index");
	lua_pushvalue(L, -2);
	lua_settable(L, -3);
	
	lua_setmetatable(L, -2);
	
	return 1;
}

int Game_run(lua_State* L)
{
	Game** ud = (Game**) lua_touserdata(L,1);
	(*ud)->run();
	return 0;
}
